package com.changgou.seckill.web.controller;

import com.changgou.entity.Result;
import com.changgou.seckill.feign.SeckillGoodsFeign;
import com.changgou.seckill.pojo.SeckillGoods;
import com.changgou.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author kfzhao
 * @version 1.0
 * @className SeckillGoodsController
 * @description
 * @date 2022/1/6 0:41
 */
@Controller
@RequestMapping("/wseckillgoods")
public class SeckillGoodsController {

    @Autowired
    private SeckillGoodsFeign seckillGoodsFeign;

    /**
     * 跳转秒杀首页
     *
     * @param
     * @return
     * @throws
     * @description
     * @author kfzhao
     * @date 2022/1/6 0:42
     */
    @RequestMapping("/toIndex")
    public String toIndex() {
        return "seckill-index";
    }

    /**
     * 获取秒杀时间段集合信息
     *
     * @param
     * @return java.util.List<java.lang.String>
     * @throws
     * @description
     * @author kfzhao
     * @date 2022/1/6 0:42
     */
    @RequestMapping("/timeMenus")
    @ResponseBody
    public List<String> dateMenus() {
        // 获取当前时间段的相关信息集合
        List<Date> dateMenus = DateUtil.getDateMenus();
        List<String> result = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        for (Date dateMenu : dateMenus) {
            String format = simpleDateFormat.format(dateMenu);
            result.add(format);
        }
        return result;
    }


    @RequestMapping("/list")
    @ResponseBody
    public Result<List<SeckillGoods>> list(String time) {
        return seckillGoodsFeign.list(DateUtil.formatStr(time));
    }
}
